using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class FireBall : MonoBehaviour
{
    public Rigidbody2D rb;
    public Transform target;

    private void Start()
    {
        rb.velocity = new Vector2(5, 0);
        target = GameObject.Find("Enemy").transform;
    }

    private void Update()
    {
        //Debug.Log(Vector2.Distance(target.position, transform.position));
        if (Vector2.Distance(target.position, transform.position) < 0.3f)
        {
            target.gameObject.GetComponent<CharacterStats>().BeDamaged(5);
            Destroy(this.gameObject);
        }
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.GetComponent<Enemy>() != null)
        {
            other.gameObject.GetComponent<CharacterStats>().BeDamaged(5);
            Destroy(this.gameObject);
        }
    }
}
